package com.yi.serviceprice.controller;


import com.yi.internalcommon.dto.PriceRule;
import com.yi.internalcommon.dto.ResponseResult;
import com.yi.internalcommon.request.PriceRuleIsNewRequest;
import com.yi.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 田毅
 * @since 2022-12-21
 */
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {

    @Autowired
    private PriceRuleService priceRuleService;

    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRule priceRule) {
        return priceRuleService.add(priceRule);
    }

    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule) {
        return priceRuleService.edit(priceRule);
    }

    /**
     * 查询最新版本的计价规则
     * GET /price-rule/get-newest-version
     * 接口ID：58608483
     * 接口地址：https://www.apifox.cn/link/project/1283880/apis/api-58608483
     */
    @GetMapping("/get-newest-version")
    public ResponseResult getNewestVersion(@RequestParam String fareType) {
        return priceRuleService.getNewestVersion(fareType);
    }

    /**
     * 判断当前计价规则是否为最新
     * GET /price-rule/is-new
     * 接口ID：58608487
     * 接口地址：https://www.apifox.cn/link/project/1283880/apis/api-58608487
     */
    @PostMapping("/is-new")
    public ResponseResult<Boolean> isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest) {
        return priceRuleService.isNew(priceRuleIsNewRequest.getFareType(),priceRuleIsNewRequest.getFareVersion());
    }

    /**
     * 根据城市编码和车型查询计价规则是否存在
     * @param priceRule
     * @return
     */
    @PostMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestBody PriceRule priceRule) {
        return priceRuleService.ifExists(priceRule);
    }
}
